<?PHP
/* This is where you would inject your sql into the database 
but we're just going to format it and send it back 
*/ 

include '../../m/constants.php';
global $conf;
$conf->debug=false;
foreach ($_GET['listItem'] as $position => $item) : 
  $sql[] = "UPDATE `playlist_media` SET `order` = $position WHERE `media` = $item"; 


//get ID
	unset($where);
	$w[0]='playlist';
	$w[1]=$_GET['playlist'];
	$w[2]='=';
	$where[]=$w;
	
	$w[0]='media';
	$w[1]=$item;
	$w[2]='=';
	$where[]=$w;
	$data=get_sql('playlist_media','id',$where,NULL);
	$id=current($data);
	$id=$id['id'];
	
$post['order']=$position;
//echo $item;


process_sql_post($post,'playlist_media','update','id',$id);
endforeach; 
echo 'Saved';
//print_r ($sql); 
?>